home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / HEXDUMP.BAT < prev    next >
DOS Batch File  |  1993-08-09  |  1KB  |  45 lines

  1. @echo off
  2. REM **********************************************************************
  3. REM *** HexDump.bat - Hexidecimal dump of the contents of a file. This ***
  4. REM ***               examples program uses the CEnvi file routines.   ***
  5. REM **********************************************************************
  6. cenvi %0.bat %1 %2
  7. GOTO CENVI_EXIT
  8.  
  9. main(argc,argv)
  10. {
  11.    if ( 2 != argc ) {
  12.       Instructions()
  13.    } else if ( NULL == (fp = fopen(argv[1],"rb")) ) {
  14.       printf("Could not open file \"%s\" for hex output.\a\n",argv[1])
  15.    } else {
  16.       dump(fp)
  17.       fclose(fp)
  18.    }
  19. }
  20.  
  21. dump(file)
  22. {
  23.    Unprintables = "\a\b\t\r\n\032\033"
  24.    for ( offset = 0; 0 < (count = fread(data,16,file)); offset += 16 ) {
  25.       // display hex offset in file
  26.       printf("%06X  ",offset)
  27.       // display hex value for each number
  28.       for ( i = 0; i < count; i++ )
  29.          printf("%02X ",data[i])
  30.       // fill in any extra gaps if count < 16
  31.       while( i++ < 16 )
  32.          printf("   ")
  33.       // display ascii value for each printable character
  34.       // substitute a period for unprintable characters
  35.       data[count] = 0; // string must be null-terminated
  36.       while( (UnprintableIndex = strcspn(data,Unprintables)) < count )
  37.          data[UnprintableIndex] = '.';
  38.       printf("   %s\n",data)
  39.       if ( count < 16 )
  40.          break
  41.    }
  42. }
  43.  
  44. :CENVI_EXIT
  45.